package com.webSite.demo.cy.indie.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.webSite.demo.cy.bean.HomeNews;
import com.webSite.demo.cy.mapper.HomeNewsMapper;
import com.webSite.demo.cy.service.CommonService;

@Controller  
@EnableAutoConfiguration
public class NewsController {

	@Autowired
	HomeNewsMapper homeNewsMapper;
	@Autowired
	CommonService commonService;

	@RequestMapping("/news.html")  
    String news(Model model) {
		List<HomeNews> newList = homeNewsMapper.findAllInfo();
		if(!newList.isEmpty()) {
			model.addAttribute("newList", newList);
		}
		model.addAttribute("MetaList", commonService.findMete("新闻中心"));
		model.addAttribute("menu", "news");
        return "news";
    }
	
	@RequestMapping("/{id}.html")  
    String newsshow(@PathVariable int id,Model model) {
		HomeNews news = homeNewsMapper.findOne(id);
		model.addAttribute("MetaList", commonService.findMete("新闻中心"));
		model.addAttribute("newsList", commonService.findRandData(id, 3));
		model.addAttribute("menu", "news");
		model.addAttribute("news", news);
        return "newsshow";
    }
	
}
